<?php
include 'lib/controllerWithoutGetOrPost.php';
include 'lib/LoggedIn.php';
$loggedIn = new LoggedIn();
$loggedIn->setPermission = "Admin Area";
if(!$loggedIn->check()) {
    echo $loggedIn->message();
} else {
include("header2.php");

$query = "Select FuneralDetails.ID as FuneralDetailsID, FuneralHomeID, ContactFirstName, ContactLastName, TelephoneDD, Telephone, Address1, Address2, Suburb, Fax, Email, AddListingNotify, Web, Blurb, CountryID, RegionID, CityTownID, FuneralHome.ID as FuneralHomeID, FuneralHome.Name as FuneralHomeName from FuneralDetails left join FuneralHome on FuneralDetails.FuneralHomeID = FuneralHome.ID order by FuneralHome.Name ASC";


//$query = "Select Charity.`ID`, Charity.`Name`, `Email`, `Web`, `DonateDirect`, `ShowCharity`, `ContactFirstName`, `ContactLastName`, `Suburb`, `Address1`, `Address2`, `Telephone`, `TelephoneDD`, `Fax`, `Blurb`, Country.`Name` as `CountryName`, CityTown.`Name` as CityTownName from Charity left join Country on Charity.CountryID = Country.ID left join CityTown on CityTown.ID = Charity.CityTownID";

// Perform Query
$result = mysql_query($query, $link);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
echo "<table style=\"width:3000px\"><thead><tr><th>ID</th><th>Name</th><th>Listing Notify</th><th>Email</th><th>Web</th><th>First Name</th><th>Last Name</th><th>Suburb</th><th>Address 1</th><th>Address 2</th><th>Telephone</th><th>Telephone DD</th><th>Fax</th><th style=\"width:400px\">Blurb</th></tr></thead>";
while ($row = mysql_fetch_assoc($result)) {

    echo "<tr><td style=\"width:100px;\"><a rel=\"external\" href=\"editfuneralhome.php?id=".$row['FuneralDetailsID']."\">Edit ID: ".$row['FuneralDetailsID']."</a></td>";
    echo "<td style=\"overflow:hidden\">".$row['FuneralHomeName']."</td>";
    echo '<td style="overflow:hidden;text-align: right;"><input type="checkbox" disabled="disabled"'.(!empty($row['AddListingNotify'])?' checked="checked"':'').'</td>';
    echo "<td style=\"overflow:hidden\">".$row['Email']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Web']."</td>";
	//echo "<td style=\"overflow:hidden\">".$row['DonateDirect']."</td>";
	//echo "<td style=\"overflow:hidden\">".$row['ShowCharity']."</td>";
	//echo "<td style=\"overflow:hidden\">".$row['CountryName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['ContactFirstName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['ContactLastName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Suburb']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Address1']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Address2']."</td>";
    echo "<td style=\"overflow:hidden\">".$row['Telephone']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['TelephoneDD']."</td>";
	//echo "<td style=\"overflow:hidden\">".$row['CityTownName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Fax']."</td>";
	echo "<td style=\"width:300px;\">".$row['Blurb']."</td>";
	echo "</tr>";
}
echo "</table></body></html>";
}
?>
